/**
 * @description 组织机构-新增弹窗
 * @author 李艳
 */

import React, {Component} from 'react'
import {Checkbox, Form, Input, InputNumber, Modal, Row} from 'antd';

const FormItem = Form.Item;

class EditOrganizationModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      modalVisible: false,
      confirmLoading: false,
    }
  }

  handleClose = () => {
    this.props.form.resetFields();
  };

  componentDidMount() {
    this.props.onRef(this);

  }

  render() {
    const formItemLayout = {
      labelCol: {
        span: 7
      },
      wrapperCol: {
        span: 14
      },
    };

    const {confirmLoading, modalVisible, handleOk, handleCancel, defaultValue} = this.props;
    const {getFieldDecorator} = this.props.form;
    let title = "新增节点";
    return (
      <div>
        <Modal title={title}
               visible={modalVisible}
               onOk={handleOk}
               onCancel={handleCancel}
               width={400}
               afterClose={this.handleClose}
               confirmLoading={confirmLoading}
               maskClosable={false}
        >


              <FormItem
                {...formItemLayout}
                style={{display: 'none'}}
                label="parentId">
                {getFieldDecorator('parentId', {
                  initialValue: defaultValue.parentId ? defaultValue.parentId : "",
                })(
                  <Input/>
                )}
              </FormItem>
            <Row>
              <FormItem
                {...formItemLayout}
                label="父节点">
                {getFieldDecorator('parentName', {
                  initialValue: defaultValue.parentName ? defaultValue.parentName : "",
                })(
                  <Input disabled={true}/>
                )}
              </FormItem>
            </Row>
            <Row>
              <FormItem
                {...formItemLayout}
                label="名称">
                {getFieldDecorator('name', {
                  initialValue: defaultValue.name ? defaultValue.name : "",
                  rules: [{required: true, message: '请填写名称!'}]
                })(
                  <Input maxLength={50}/>
                )}
              </FormItem>
            </Row>
            <Row>
              <FormItem
                {...formItemLayout}
                label="排序">
                {getFieldDecorator('rank', {
                  initialValue: defaultValue.rank ? defaultValue.rank : 0,
                  rules: [{required: true, message: '请填写排序!'}]
                })(
                  <InputNumber maxLength={9} precision={0} min={0}  style={{width: "100%"}}/>
                )}
              </FormItem>
            </Row>
            <Row>
              <FormItem
                {...formItemLayout}
                label="冻结">
                {getFieldDecorator('frozen', {
                  valuePropName: 'checked',
                })(
                  <Checkbox/>
                )}
              </FormItem>
            </Row>
        </Modal>
      </div>
    );
  }
}

EditOrganizationModal = Form.create()(EditOrganizationModal);
export default EditOrganizationModal;
